
const my = {
  state: {
    // 存储浏览历史
    histroy: [],
    // 存储我的收藏
    favourite: [],
    // 是否已登录
    logined: false
  },

  mutations: {

    SET_HISTROY: (state, histroy) => {
      state.histroy.unshift({ createTime: new Date(), histroy: histroy })
    },
    SET_FAVOURITE: (state, favourite) => {
      state.favourite.unshift(favourite)
    },
    SET_LOGIN: (state, login) => {
      state.logined = login
    }

  },

  actions: {
    setHistroy({ commit }, histroy) {
      return new Promise(resolve => {
        commit('SET_HISTROY', histroy)
      })
    },

    setFavourite({ commit }, favourite) {
      return new Promise(resolve => {
        commit('SET_FAVOURITE', favourite)
      })
    },

    setLogin({ commit }, login) {
      return new Promise(resolve => {
        commit('SET_LOGIN', login)
      })
    }
  }
}

export default my
